// components/publishRight/publishRight.js

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    wxid: {
      type: String,
      value: ""
    },
    avid: {
      type: String,
      value: ""
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    img: "",
    category:"",
    ided:"",
    avwxid:"",
    categoryy:"",
    master:""
  },

  /**
   * 组件的方法列表
   */ observers: {
    'wxid': function() {
      // 每次 setData 都触发
      var that=this
      wx.request({
        url: 'https://www.linjianyi.link/getCategoryimg',
        data:{
          avid:this.properties.avid
        },
        success(res){
          that.setData({
            category:res.data
          })
        }
      })
wx.request({
  url: 'https://www.linjianyi.link/judgeHeart',
  data:{
    wxid:this.properties.wxid,
    avid:this.properties.avid
  },
  success(res){
   if(res.data=="no"){
that.setData({
  img:"../../images/activity/nolike.png"
})
   }
   else{
     that.setData({
      img:"../../images/activity/like.png"
     })

   }
  }
})

    }},


   
  methods: {
    clickchange() {
      if (this.data.img == "../../images/activity/nolike.png") {
        this.setData({
          img: "../../images/activity/like.png"
        })
      wx.request({
        url: 'https://www.linjianyi.link/addlove',
        data:{
          avid:this.properties.avid,
          wxid:this.properties.wxid,
        },
        success(){
          
        }
      })
      } 
      
      
      
      else {
        var that=this
        wx.showModal({
          title: '提示',
          content: '确定取消关注此活动?',
          success: function (res) {
            if (res.confirm) {//这里是点击了确定以后
              that.setData({
                img: "../../images/activity/nolike.png"
              })
           
              wx.request({
                url: 'https://www.linjianyi.link/reducelove',
                data:{
                  avid:that.properties.avid,
                  wxid:that.properties.wxid
                },
                success(){
                  wx.reLaunch({
                    url: '../../pages/mylove/mylove',
                  })
                }
              })
            } else {//这里是点击了取消以后
              console.log('用户点击取消')
            }
          }
        })




        
      }

    },
    inComment(){
      var that=this
      //从这边获得avid所属的用户,并且吧该ided传给聊天界面
      wx.request({
        url: 'https://www.linjianyi.link/getwxidAndimg',
        data:{
          avid:this.properties.avid
        },
        success(res){
    that.setData({
      master:res.data[0][6],
avwxid:res.data[0][3],
categoryy:res.data[0][2]
      })
 
      wx.navigateTo({
        url: '../../pages/talk/talk?avid='+that.properties.avid+'&avwxid='+that.data.avwxid+'&categoryy='+that.data.categoryy+'&master='+that.data.master
      })
        }
      })
 

    },

   
  }
})